#include "cudiskupdater.h"
#include "cconfig.h"
#include <QDebug>
#include <QTimer>
#include <QStorageInfo>
#include <QDir>

CUdiskUpdater::CUdiskUpdater(QObject *parent) : QObject(parent)
{
    CConfig cfg;
    QTimer* timer = new QTimer(this);
    timer->setInterval(cfg.UdiskInterval());
    timer->setSingleShot(false);
    connect(timer, SIGNAL(timeout()), this, SLOT(CheckUpdate()));
    timer->start();
}

void CUdiskUpdater::CheckUpdate()
{
    QString app_name = CConfig().AppName()+".*";

    for(QStorageInfo& i : QStorageInfo::mountedVolumes())
    {
        QStringList apps = QDir(i.rootPath()).entryList({app_name});
        if(apps.size() != 1) continue;
        emit updateAvailable(i.rootPath() + "/" + apps.first());
        break;
    }
}
